import React, {Component} from 'react'
import {Form, Input} from 'antd'
import PropTypes from 'prop-types'
const Item = Form.Item
/*
更新分类的 Form 组件
*/
class UpdateForm extends Component {
    myRef = React.createRef();
    static propTypes = {
        categoryName: PropTypes.string,
        setForm: PropTypes.func.isRequired,
    }
    change = ()=> {
        // console.log(this.props.setForm)
        this.props.setForm(this.myRef.current.state.value)
    }
    render() {
        const {categoryName} = this.props
        return (
            <Form key={categoryName}>
                <Item
                    name="category"
                    rules={[
                    {
                        required: true,
                        message: 'Please input!',
                    },
                ]}>
                    <Input ref={this.myRef} onBlur={this.change} placeholder='请输入分类名称' defaultValue={categoryName}/>
                </Item>
            </Form>
        )
    }
}
export default UpdateForm